package base;

import java.util.*;

/**
 * This class is used to handle with sales
 *
 * @author XFishalways
 */
public class Store_Sales {

    private Vector<Order> orders;

    /**
     * Constructs an empty collection of {@link Order}
     */
    public Store_Sales() {
        orders = new Vector<>();
    }

    /**
     * Add a {@link Order} object to this collection
     *
     * @param order the {@link Order} object
     */
    public void addOrder(Order order) {
        orders.add(order);
    }

    /**
     * Returns an iterator on orders in this sales
     *
     * Returns an {@link Iterator}
     */
    public Iterator<Order> getOrdersIterator() {
        return orders.iterator();
    }

    /**
     * Returns the {@link Order} object with the specified
     * <code>id</code>.
     *
     * @param orderNo  the number of the order.
     * @return  The {@link Order} object with a specified number.
     *          Returns <code>null</code> if the object with the number is not found.
     */
    public Order getOrder(String orderNo) {
        for (Iterator<Order> i = getOrdersIterator(); i.hasNext();) {
            Order order = i.next();
            if (order.getOrderNo().equals(orderNo)) {
                return order;
            }
        }
        return null;
    }

    /**
     * Returns the total amount of {@link Order} in this collection
     *
     * @return Returns the total amount of {@link Order} in this collection
     */
    public int getNumberOfOrders() {
        return orders.size();
    }

    /**
     * Output the information of sales
     */
    public void showSales() {
        int Num=0;
        for(Order O:orders) {
            System.out.println("Order "+(++Num)+":");
            O.showOrder();
        }
    }
}